package com.yds;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @ClassName MapUtil
 * @Description Map工具类
 * @Author wed
 * @Date 2022/10/28
 * @Version 1.0
 **/
public class MapUtils {
    /**
     * 获取map中最大的key
     *
     * @param map
     * @return
     */
    public static <T> Integer getMaxKey(Map<Integer, List<T>> map) {
        if (map == null) {
            return null;
        }
        Set<Integer> set = map.keySet();
        Object[] obj = set.toArray();
        Arrays.sort(obj);
        return Integer.parseInt(obj[obj.length - 1].toString());
    }

    /**
     * 获取map中最小的key
     *
     * @param map
     * @return
     */
    public static <T> Integer getMinKey(Map<Integer, List<T>> map) {
        if (map == null) {
            return null;
        }
        Set<Integer> set = map.keySet();
        Object[] obj = set.toArray();
        Arrays.sort(obj);
        return Integer.parseInt(obj[0].toString());
    }
}
